package org.concordia.wsdl.helper;

import java.util.LinkedList;
import java.util.List;

import org.concordia.wsdl.model.WebService;

/**
 * 
 * @author ericzhao
 *
 */
public abstract class ListUtils {
	
	/**
	 * return a clone of original list
	 * @param list
	 * @return
	 */
	public static List<String> copyList(List<String> list){
		List<String> copy = new LinkedList<String>();
		for(String s : list){
			String copyStr = new String(s);
			copy.add(copyStr);
		}
		return copy;
	}
	
	/**
	 * mathematical join of list 1 and list 2 
	 * @param l1
	 * @param l2
	 * @return
	 */
	public static List<String> join(List<String> l1, List<String> l2){
		List<String> list = new LinkedList<String>();
		
		for(String s1 : l1){
			for(String s2 : l2){
				if(s1.equals(s2)){
					String s = new String(s1);
					list.add(s);
				}
			}
		}
		
		return list;
	}

	/**
	 * sub params in list 2 from list 1
	 * @param l1
	 * @param l2
	 * @return
	 */
	public static List<String> sub(List<String> l1, List<String> l2){
		
		List<String> list = (List<String>) ListUtils.copyList(l1);
		for(String p : l2){
			if(list.contains(p)){
				list.remove(p);
			}
		}
		
		return list;
	}
	
	/**
	 * mathematical union operation for two lists
	 * @param l1
	 * @param l2
	 * @return
	 */
	public static List<String> union(List<String> l1, List<String> l2){
		
		List<String> list = (List<String>) ListUtils.copyList(l1);
		for(String p: l2){
			list.add(new String(p));
		}
		
		return list;
	}
	
	/**
	 * mathematical union operation for two lists (Type: Web Service)
	 * @param l1
	 * @param l2
	 * @return
	 */
	public static List<WebService> unionWS (List<WebService> l1, List<WebService> l2){
		
		List<WebService> list = new LinkedList<WebService>();
		
		for(WebService ws : l1){
			list.add(ws);
		}
		for(WebService ws: l2){
			list.add(ws);
		}
		
		return list;
	}
	
	/**
	 * sub params in list 2 from list 1 (Type: Web Service)
	 * @param l1
	 * @param l2
	 * @return
	 */
	public static List<WebService> subWS(List<WebService> l1, List<WebService> l2){
		
		List<WebService> list = new LinkedList<WebService>();
		
		for(WebService ws : l1){
			list.add(ws);
		}
		
		for(WebService ws : l2){
			if(list.contains(ws)){
				list.remove(ws);
			}
		}
		
		return list;
	}
	
	/**
	 * return a clone of original list (Type: Web Service)
	 * @param list
	 * @return
	 */
	public static List<WebService> copyListWS(List<WebService> list){
		List<WebService> copy = new LinkedList<WebService>();
		
		for(WebService ws : list){
			copy.add(ws);
		}
		
		return copy;
	}
	
	
}
/**
 * $Log: Utilities.java,v $
 *
 */